package com.aichongbang.acb.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
@ApiModel(value = "前台数据封装")
public class ResultVO implements Serializable {
    @ApiModelProperty("成功或者失败的代码号")
    private Integer code;
    @ApiModelProperty("成功或者失败的信息")
    private String message;
    @ApiModelProperty("返回前台的值")
    private Object data;
    @ApiModelProperty("返回集合的数量")
    private Long count;
    @ApiModelProperty("返回分页之后的页数")
    private Long pages;

    public ResultVO(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultVO(ResultCode resultCode, Object data){
        this.code = resultCode.code();
        this.message = resultCode.message();
        this.data = data;
    }
    public ResultVO(ResultCode resultCode){
        this.code = resultCode.code();
        this.message = resultCode.message();
    }
    // 返回成功
    public static ResultVO success(){
        ResultVO resultVO = new ResultVO(ResultCode.SUCCESS);
        return resultVO;
    }
    // 返回成功
    public static ResultVO success(Object data){
        ResultVO resultVO = new ResultVO(ResultCode.SUCCESS,data);
        return resultVO;
    }
    // 返回失败
    public static ResultVO fail(ResultCode resultCode){
        ResultVO resultVO = new ResultVO(resultCode);
        return resultVO;
    }
    // 返回失败
    public static ResultVO fail(Integer code, String message){
        ResultVO resultVO = new ResultVO(code,message);
        return resultVO;
    }
    // 返回失败
    public static ResultVO fail(ResultCode resultCode, Object data){
        ResultVO resultVO = new ResultVO(resultCode,data);
        return resultVO;
    }
}
